package com.xiefengf.rabbitmq.producer.controller;

import com.xiefengf.rabbitmq.producer.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author xiefengf
 * @version 1.0
 * @date 2024/1/10 23:58
 *
 */
@Slf4j
@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    private FanoutProductService fanoutProductService;

    @Resource
    private DirectProductService directProductService;

    @Resource
    private TopicProductService topicProductService;

    @Resource
    private TtlProductService ttlProductService;

    @Resource
    private AckProductService ackProductService;

    @Resource
    private BatchProductService batchProductService;

    /**
     * http://localhost:9992/rabbitmq/product/fanout/makeOrder?userId=111&productId=222&msg=SSS
     * @param userId
     * @param productId
     * @param msg
     * @return
     */
    @GetMapping("/fanout/makeOrder")
    public String fanoutMakeOrder(@RequestParam Integer userId,@RequestParam Integer productId,@RequestParam String msg){
        fanoutProductService.makeOrder(userId,productId,msg);
        return msg;
    }

    /**
     * http://localhost:9992/rabbitmq/product/direct1/makeOrder?userId=111&productId=222&msg=AAA
     * @param userId
     * @param productId
     * @param msg
     * @return
     */
    @GetMapping("/direct1/makeOrder")
    public String direct1MakeOrder(@RequestParam Integer userId,@RequestParam Integer productId,@RequestParam String msg){
        directProductService.makeOrder1(userId,productId,msg);
        return msg;
    }

    /**
     * http://localhost:9992/rabbitmq/product/direct2/makeOrder?userId=111&productId=222&msg=BBB
     * @param userId
     * @param productId
     * @param msg
     * @return
     */
    @GetMapping("/direct2/makeOrder")
    public String direct2MakeOrder(@RequestParam Integer userId,@RequestParam Integer productId,@RequestParam String msg){
        directProductService.makeOrder2(userId,productId,msg);
        return msg;
    }

    /**
     * http://localhost:9992/rabbitmq/product/direct3/makeOrder?userId=111&productId=222&msg=CCC
     * @param userId
     * @param productId
     * @param msg
     * @return
     */
    @GetMapping("/direct3/makeOrder")
    public String direct3MakeOrder(@RequestParam Integer userId,@RequestParam Integer productId,@RequestParam String msg){
        directProductService.makeOrder3(userId,productId,msg);
        return msg;
    }

    /**
     * http://localhost:9992/rabbitmq/product/topic1/makeOrder?userId=111&productId=222&msg=ZZZ
     * @param userId
     * @param productId
     * @param msg
     * @return
     */
    @GetMapping("/topic1/makeOrder")
    public String topic1MakeOrder(@RequestParam Integer userId,@RequestParam Integer productId,@RequestParam String msg){
        topicProductService.makeOrder1(userId,productId,msg);
        return msg;
    }

    /**
     * http://localhost:9992/rabbitmq/product/topic2/makeOrder?userId=111&productId=222&msg=XXX
     * @param userId
     * @param productId
     * @param msg
     * @return
     */
    @GetMapping("/topic2/makeOrder")
    public String topic2MakeOrder(@RequestParam Integer userId,@RequestParam Integer productId,@RequestParam String msg){
        topicProductService.makeOrder2(userId,productId,msg);
        return msg;
    }

    /**
     * http://localhost:9992/rabbitmq/product/topic3/makeOrder?userId=111&productId=222&msg=CCC
     * @param userId
     * @param productId
     * @param msg
     * @return
     */
    @GetMapping("/topic3/makeOrder")
    public String topic3MakeOrder(@RequestParam Integer userId,@RequestParam Integer productId,@RequestParam String msg){
        topicProductService.makeOrder3(userId,productId,msg);
        return msg;
    }

    /**
     * http://localhost:9992/rabbitmq/product/ttl1/makeOrder?userId=111&productId=222&msg=CCC
     * @param userId
     * @param productId
     * @param msg
     * @return
     */
    @GetMapping("/ttl1/makeOrder")
    public String ttl1MakeOrder(@RequestParam Integer userId,@RequestParam Integer productId,@RequestParam String msg){
        ttlProductService.makeOrder1(userId,productId,msg);
        return msg;
    }

    /**
     * http://localhost:9992/rabbitmq/product/ttl2/makeOrder?userId=111&productId=222&msg=CCC
     * @param userId
     * @param productId
     * @param msg
     * @return
     */
    @GetMapping("/ttl2/makeOrder")
    public String ttl2MakeOrder(@RequestParam Integer userId,@RequestParam Integer productId,@RequestParam String msg){
        ttlProductService.makeOrder2(userId,productId,msg);
        return msg;
    }

    /**
     * http://localhost:9992/rabbitmq/product/ack1/makeOrder?userId=111&productId=222&msg=CCC
     * @param userId
     * @param productId
     * @param msg
     * @return
     */
    @GetMapping("/ack1/makeOrder")
    public String ack1MakeOrder(@RequestParam Integer userId,@RequestParam Integer productId,@RequestParam String msg){
        ackProductService.makeOrder1(userId,productId,msg);
        return msg;
    }

    /**
     * http://localhost:9992/rabbitmq/product/batch1/makeOrder?userId=111&productId=222&msg=CCC
     * @param userId
     * @param productId
     * @param msg
     * @return
     */
    @GetMapping("/batch1/makeOrder")
    public String batch1MakeOrder(@RequestParam Integer userId,@RequestParam Integer productId,@RequestParam String msg){
        batchProductService.syncSend1(userId,productId,msg);
        return msg;
    }

    /**
     * http://localhost:9992/rabbitmq/product/batch2/makeOrder?userId=111&productId=222&msg=CCC
     * @param userId
     * @param productId
     * @param msg
     * @return
     */
    @GetMapping("/batch2/makeOrder")
    public String batch2MakeOrder(@RequestParam Integer userId,@RequestParam Integer productId,@RequestParam String msg){
        batchProductService.syncSend2(userId,productId,msg);
        return msg;
    }

}
